package fr.vvins.core.user.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import fr.vvins.core.user.entity.User;

@Repository
public interface UserRepository extends CrudRepository<User, Integer> {

	@Query("select u from User u join u.userCommunities as com where com.userCommunityToken=?1")
	User findByCommunityToken(String id);

	@Query("select u from User u join u.userCommunities as com where com.userCommunityToken in ?1")
	List<User> findByCommunityTokens(List<String> friendsId);

	@Query("select u from User u join u.followingUser as fu where fu.id=?1")
	List<User> getFollowers(Integer id);

	@Query("from User u where u.login = ?1")
	List<User> findByLogin(String login);

	@Query("from User u where u.email = ?1")
	User findByEmail(String email);

	@Query("from User where id in ?1")
	List<User> findByUserIds(List<Integer> targetUsersId);

	@Query("select u from User u join u.followingUser fu where fu.id=?1")
	List<User> findByFollowers(Integer targetUserId);

	@Query("select user.followingUser from User user where user.id=?1")
	List<User> findByFollowing(Integer tokenUserId);

}
